﻿/*  Copyright 2012 PerceiveIT Limited
 *  This file is part of the Scryber library.
 *
 *  You can redistribute Scryber and/or modify 
 *  it under the terms of the GNU Lesser General Public License as published by
 *  the Free Software Foundation, either version 3 of the License, or
 *  (at your option) any later version.
 * 
 *  Scryber is distributed in the hope that it will be useful,
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *  GNU Lesser General Public License for more details.
 * 
 *  You should have received a copy of the GNU Lesser General Public License
 *  along with Scryber source code in the COPYING.txt file.  If not, see <http://www.gnu.org/licenses/>.
 * 
 */

using System;
using System.Collections.Generic;
using System.Text;
using Scryber.Styles;
using Scryber.Drawing;

namespace Scryber.Components
{
    /// <summary>
    /// All the heading classes (H1,H2..) inherit from this base class which is 
    /// itself a text base class
    /// </summary>
    [PDFParsableComponent("Heading")]
    public abstract class PDFHeadingBase : PDFPanel
    {

        private PDFLabel textlbl = null;

        [PDFAttribute("text")]
        public string Text
        {
            get
            {
                if (null == this.textlbl)
                    return string.Empty;
                else
                    return this.textlbl.Text;
            }
            set
            {
                if (string.IsNullOrEmpty(value))
                {
                    if (null != this.textlbl)
                        this.Contents.Remove(this.textlbl);
                    this.textlbl = null;
                }
                else
                {
                    if (null == this.textlbl)
                    {
                        this.textlbl = new PDFLabel();
                        if (this.Contents.Count == 0)
                            this.Contents.Add(this.textlbl);
                        else
                            this.Contents.Insert(0, this.textlbl);
                    }
                    this.textlbl.Text = value;
                }
                
            }
        }

        [PDFElement()]
        [PDFArray(typeof(PDFComponent))]
        public override PDFComponentList Contents
        {
            get
            {
                return base.Contents;
            }
        }

        

        public PDFHeadingBase(PDFObjectType type)
            : base(type)
        {
        }

        protected static PDFStyle GetBaseStyles(PDFUnit fontsize, bool bold, bool italic)
        {
            PDFStyle fs = new PDFStyle();
            fs.Font.FontSize = fontsize;
            fs.Font.FontBold = bold;
            fs.Font.FontItalic = italic;
            fs.Position.PositionMode = PositionMode.Block;
            fs.Overflow.Split = OverflowSplit.Never;
            return fs;
        }

        
    }

    [PDFParsableComponent("H1")]
    public class PDFHead1 : PDFHeadingBase
    {

        public PDFHead1()
            : this(PDFObjectTypes.H1)
        {
        }

        protected PDFHead1(PDFObjectType type)
            : base(type)
        {
        }

        protected override PDFStyle GetBaseStyle()
        {
            return PDFHeadingBase.GetBaseStyles(36,true, false);
        }
    }

    [PDFParsableComponent("H2")]
    public class PDFHead2 : PDFHeadingBase
    {

        public PDFHead2()
            : this(PDFObjectTypes.H2)
        { }

        protected PDFHead2(PDFObjectType type)
            : base(type)
        {
        }

        protected override PDFStyle GetBaseStyle()
        {
            return PDFHeadingBase.GetBaseStyles(30, true, true);
        }
    }

    [PDFParsableComponent("H3")]
    public class PDFHead3 : PDFHeadingBase
    {

        public PDFHead3()
            : this(PDFObjectTypes.H3)
        { }

        protected PDFHead3(PDFObjectType type)
            : base(type)
        {
        }

        protected override PDFStyle GetBaseStyle()
        {
            return PDFHeadingBase.GetBaseStyles(24, true, false);
        }
    }

    [PDFParsableComponent("H4")]
    public class PDFHead4 : PDFHeadingBase
    {

        public PDFHead4()
            : this(PDFObjectTypes.H4)
        { }

        protected PDFHead4(PDFObjectType type)
            : base(type)
        {
        }

        protected override PDFStyle GetBaseStyle()
        {
            return PDFHeadingBase.GetBaseStyles(20, true, true);
        }
    }

    [PDFParsableComponent("H5")]
    public class PDFHead5 : PDFHeadingBase
    {

        public PDFHead5()
            : this(PDFObjectTypes.H5)
        { }

        protected PDFHead5(PDFObjectType type)
            : base(type)
        {
        }

        protected override PDFStyle GetBaseStyle()
        {
            return PDFHeadingBase.GetBaseStyles(17, true, false);
        }
    }

    [PDFParsableComponent("H6")]
    public class PDFHead6 : PDFHeadingBase
    {

        public PDFHead6()
            : this(PDFObjectTypes.H6)
        { }

        protected PDFHead6(PDFObjectType type)
            : base(type)
        {
        }

        protected override PDFStyle GetBaseStyle()
        {
            return PDFHeadingBase.GetBaseStyles(15, true, true);
        }
    }
}
